home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / image.ed / bigpixel.c next >
C/C++ Source or Header  |  1985-10-26  |  6KB  |  193 lines

  1.  
  2. /************* bigpixel2.c ***************/
  3. #include "intuall.h"
  4. #include "imageedit.h"
  5.  
  6. extern struct RastPort *rp;
  7. extern struct Screen *screen;
  8. extern struct Window *w;
  9. extern struct frame f[]; 
  10. extern SHORT framewidth, frameheight, editright, editbottom;
  11. extern SHORT bobdepth;
  12.  
  13.  
  14. SHORT zeros[41]=0;
  15.  
  16.         /* is a variable within a specified range? */
  17.  
  18.  
  19. /* ******************************************************************** */
  20. /* draw a 3-by-3 version of a pixel within a 4-by-4 area... the mouse
  21.    reporting will give us positions within the rectangle... have to adjust
  22.    to an even boundary to assure the correct position is written
  23.    (divide by 4 and multiply by 4 to zero out last 2 bits) */
  24. /* ******************************************************************** */
  25.  
  26. bigpixel(x,y)
  27. SHORT x,y;
  28. {
  29. SHORT i,j;
  30. x = ((x >> 2)<<2);      y=((y >> 2)<<2);
  31. for(i=0; i<3; i++)
  32.    for(j=0; j<3; j++)
  33.         WritePixel(rp,x+i,y+j);
  34. return(0);
  35. }
  36.  
  37. /* create a bitmap into which the aligned object can be copied, and a
  38.  * larger bitmap into which the expansion can occur in the background
  39.  */
  40.  
  41. struct BitMap bigbitmap;
  42. struct BitMap smallbitmap;
  43. struct RastPort bigrastport;
  44. struct RastPort smallrastport;
  45. struct RastPort undorastport;
  46. struct BitMap undobitmap;
  47.  
  48. workbitmaps()
  49. {
  50.         SHORT i;
  51.  
  52.         InitRastPort(&bigrastport);
  53.         InitRastPort(&smallrastport);
  54.         InitRastPort(&undorastport);
  55.         
  56.         bigrastport.BitMap = &bigbitmap;
  57.         smallrastport.BitMap = &smallbitmap;  
  58.         undorastport.BitMap = &undobitmap;  
  59.  
  60.         InitBitMap(&bigbitmap,bobdepth,344,224);
  61.         InitBitMap(&smallbitmap,bobdepth,FRAMEWIDTH+24,FRAMEHEIGHT);
  62.         InitBitMap(&undobitmap,bobdepth,FRAMEWIDTH+24,FRAMEHEIGHT);
  63.         
  64.         for(i=0; i<bobdepth; i++)
  65.             bigbitmap.Planes[i]=(PLANEPTR)AllocRaster( 344, 224);
  66.         for(i=0; i<bobdepth; i++)
  67.             smallbitmap.Planes[i]=(PLANEPTR)AllocRaster(FRAMEWIDTH+24,
  68.                                                          FRAMEHEIGHT);
  69.         for(i=0; i<bobdepth; i++)
  70.             undobitmap.Planes[i]=(PLANEPTR)AllocRaster(FRAMEWIDTH+24,
  71.                                                          FRAMEHEIGHT);
  72.         for(i=0; i<bobdepth; i++)
  73.             if(smallbitmap.Planes[i] == 0 || bigbitmap.Planes[i] == 0 || 
  74.             undobitmap.Planes[i] == 0)
  75.                         {
  76.                         CloseWindow(w);
  77.                         CloseScreen(screen);
  78.                         exit(999);      /* out of memory */
  79.                         }
  80.  
  81.         return(0);
  82. }
  83.  
  84. FreeMyMemory()
  85. {
  86.         SHORT i;
  87.         for(i=0; i<bobdepth; i++)
  88.             FreeRaster(bigbitmap.Planes[i],344, 224);
  89.         for(i=0; i<bobdepth; i++)
  90.             FreeRaster(smallbitmap.Planes[i],FRAMEWIDTH+24, FRAMEHEIGHT);
  91.         for(i=0; i<bobdepth; i++)
  92.             FreeRaster(undobitmap.Planes[i],FRAMEWIDTH+24, FRAMEHEIGHT);
  93.         return(0);
  94. }
  95.  
  96.  
  97. /*
  98.  * copy memory expanding each bit to four bits.
  99.  * The count refers to the number of byte in the source.
  100.  *
  101.  * Special purpose routine, takes one line of source, expands into
  102.  * one line of destination bitmap for each call.
  103.  */
  104.  
  105. /* ******************************************************************** */
  106.  
  107. /* construct a table of values which translate a 1-bit wide item into
  108.    a four-bit wide item.  There are 16 entries in the table translating
  109.    4-bit values into 16 equivalent word values */
  110.  
  111. USHORT exptable[] = {   0x0000, 0x000e, 0x00e0, 0x00ee,
  112.                         0x0e00, 0x0e0e, 0x0ee0, 0x0eee,
  113.                         0xe000, 0xe00e, 0xe0e0, 0xe0ee,
  114.                         0xee00, 0xee0e, 0xeee0, 0xeeee }; 
  115.  
  116. expand(d, s, count)
  117.         PLANEPTR d,s;
  118.         register count;
  119.         {
  120.         register USHORT *dest;   /* destination array */
  121.         register UBYTE *src;     /* source array */
  122.         register UBYTE a;
  123.         /* expand 4 bits to 16 bits, twice */
  124.  
  125.         dest = (USHORT *)(( d >> 1 ) << 1);
  126.         src = (UBYTE *)s; 
  127.         
  128.         while (count)
  129.                 {
  130.                 a = *src;       
  131.                 *dest++ = exptable [ a >> 4 ];
  132.                 *dest++ = exptable [ a & 0xf ];
  133.                 src++;
  134.                 count--;
  135.                 }
  136.         }
  137.  
  138.  
  139. /* After copying the non-aligned info from the real raster into a byte-
  140.  * aligned rastport, expand this new stuff into a word-aligned rastport
  141.  * offscreen.  Then blit it from the expanded area onto the screen.
  142.  */
  143.  
  144. doexpand(n)
  145. SHORT n;
  146. {
  147.         SHORT i,j;
  148.         PLANEPTR  p, q;         /* both pointer variables */
  149.        
  150.  
  151.         ClipBlit(rp,            /* source rastport */
  152.                 f[n].xmin,      /* source location x and y */
  153.                 f[n].ymin,
  154.                 &smallrastport, /* small rastport destination rastport */
  155.                 0,              /* destination x and y */
  156.                 0,
  157.                 framewidth,     /* bit-size of rectangle */
  158.                 frameheight,
  159.                 0xc0);          /* c0 means bit-for bit in all planes */
  160.  
  161.         for(i=0; i<bobdepth; i++)
  162.            {
  163.            p = smallbitmap.Planes[i];
  164.            q = bigbitmap.Planes[i];
  165.            for(j=0; j<frameheight; j++)
  166.                 {
  167.                 expand(q,p,10);
  168.                 q += bigbitmap.BytesPerRow;
  169.                 expand(q,p,10);
  170.                 q += bigbitmap.BytesPerRow;
  171.                 expand(q,p,10);
  172.                 q += bigbitmap.BytesPerRow;
  173.                 expand(q,zeros,10);
  174.                 q += bigbitmap.BytesPerRow;
  175.                 p += smallbitmap.BytesPerRow;
  176.                 }
  177.            }
  178.  
  179.         ClipBlit(&bigrastport, 
  180.                 0,      
  181.                 0,
  182.                 rp,      
  183.                 EDITLEFT,     
  184.                 EDITTOP,
  185.                 editright-EDITLEFT,
  186.                 editbottom-EDITTOP,
  187.                 0xc0);         
  188.  
  189.  
  190.         return(0);
  191.  
  192.